package com.example.bo.homeclass.model;


import android.telecom.Call;

import com.example.bo.homeclass.MainActivity;
import com.example.bo.homeclass.beans.LoginBean;
import com.example.bo.homeclass.retrofitservice.LoginService;

import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by asus on 2018/9/13.
 */

public class UserModel {
    private LoginService service;
    private Retrofit retrofit;
    private static final String BASE_URL = "http:/172.24.10.175:8080/foodService/";
    public UserModel(){
        retrofit = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        service = retrofit.create(LoginService.class);

    }
    public void userLogin(String username, String password, final MainActivity listener){
        retrofit2.Call<LoginBean> call = service.userLogin(username,password);
        Callback<LoginBean> callback = new Callback<LoginBean>() {
            @Override
            public void onResponse(retrofit2.Call<LoginBean> call, Response<LoginBean> response) {

            }

            @Override
            public void onFailure(retrofit2.Call<LoginBean> call, Throwable t) {

            }


            public void onResponse(Call call, Response<LoginBean> response) {
                listener.onSuccess(response.body(),1);
                System.out.print(response.body().toString());
            }


            public void onFailure(Call call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
}
